using Mono.Cecil.Cil;

namespace Cil.Ast;

public sealed class NotExpression : SingleInstructionExpression
{
	public const int ValuePos = 0;
	public const int MaxNodes = 1;

	public NotExpression(Context context, Instruction position, Expression exp_value)
		: base(context, position)
	{
		// base class
		ReturnType = exp_value.ReturnType;
		WritesStack = 1;
		ReadsStack = 1;
		Nodes = new FixedList<Expression>(MaxNodes);

		// this
		Value = exp_value;
	}

	public Expression Value { get { return Nodes[ValuePos]; } set { Nodes[ValuePos] = value; value.ParentNode = this; } }

	public override string ToString()
	{
		return string.Format("~{0}", Value);
	}
}

public static partial class IlAst
{
	public static NotExpression Not(Context context, Instruction position, Expression exp_value)
	{
		return new NotExpression(context, position, exp_value);
	}
}